package cn.itcast.com.Thread;

import java.util.Arrays;
import java.util.Random;

public class ProducerTask implements Runnable{
    private Container container;

    private Food[] foodbill = {new Food("蟹黄包",3.5),new Food("肉包子",2),
                                new Food("豆沙包",1),new Food("生煎",5)};
    private Random random;
    public ProducerTask(Container container) {
        this.container = container;
        random = new Random();
    }


    @Override
    public void run() {
        synchronized (container) {
            while (true){
                if (!container.isEmpty()){
                    try {
                        container.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }else {
                    container.setFood(foodbill[random.nextInt(foodbill.length)]);
                    System.out.println(foodbill[random.nextInt(foodbill.length)]);
                    container.notify();
                }
            }
        }
    }
}
